$.fn.renderFooterMenu = function (option) {
    let _self = this;
    let defaults = {
        activeIndex: 1,
        imgPathBase:'../images/footer/',
        menus: [
            {title: '首页', url: 'home.html', icon: '1.png'},
            {title: '机构', url: 'complain.html', icon: '2.png'},
            {title: '活动', url: 'favorites.html', icon: '3.png'},
            {title: '圈子', url: 'favorites.html', icon: '4.png'}
        ],
        //是否从服务器获取 默认true 静态测试请置为false 有特使需求也可置为false然后自己拼装menus
        server: true,
        //配置链接地址
        urls:['home.html','org.html','events.html','circle.html'],
        //配置显示范围
        range:[0,3],
        callback: function() {}
    };
    let o=$.extend(defaults, option);
    //渲染
    let render=function () {
        let html = '';
        $.each(o.menus, function (i, item) {
            html += '<div class="footer-menu-item" data-url="javascript:location.replace(\''+item.url+'\')">';
            if(i===o.activeIndex){
                html +=    '<img class="active" src="'+o.imgPathBase+item.icon.replace('.png','_active.png')+'" alt="">'

            }else {
                html +=  '<img src="'+o.imgPathBase+item.icon+'" alt="">'
            }
            html +=   '<h4>'+item.title+'</h4>' +
                '</div>'
        });
        $('.footer-menu-list').html(html);
    };
    let _init = function () {
        _self.attr('id','bottom_bar');
        _self.html('<div class="footer-menu-list"></div>');
        _self.prev().css('padding-bottom','2.5rem');
        $('<link>')
            .attr({
                rel: 'stylesheet',
                type: 'text/css',
                href: '../css/jquery.footer.css'
            })
            .appendTo('head');


        if(o.server){
            API.getFirstMenu(function (data) {
                o.menus=[];
                $.each(data.datas,function (i,item) {
                    if(i>=o.range[0] && i<=o.range[1]){
                        o.menus.push({
                            title:item.name,
                            url:o.urls[i]+'?'+$.param(item),
                            icon:(i+1)+'.png'
                        });
                    }
                });
                render();
                o.callback && o.callback(data.datas);
            });
        }else {
            render();
        }
    };
    let _event = function () {

    };
    _init();
    _event();
};

